<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商户分成设置')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-config-edit" th:object="${businessShopConfig}">
            <input name="id" th:field="*{id}" type="hidden">
            <input name="shopId" th:field="*{shopId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">商户：</label>
                <div class="col-sm-8">
                    <input name="shopName" th:value="${shop.name}" class="form-control" type="text" readonly="true">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">类型</label>
                <div class="col-sm-8">
                    <select id="type"  name="type" class="form-control select2-multiple" th:with="type=${@dict.getType('shop_config_type')}" onchange="changeSelectType()">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${ businessShopConfig.type  + '' eq dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" id="divideType" th:hidden="*{type == 0}">
                <label class="col-sm-3 control-label">分成类型：</label>
                <div class="col-sm-8">
                    <select  name="divideType" class="form-control select2-multiple" style="width:100%" th:with="type=${@dict.getType('shop_config_divide_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${ businessShopConfig.DivideType + '' eq dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">数值：</label>
                <div class="col-sm-8">
                    <input name="value" th:value="${businessShopConfig.value}" class="form-control" type="text">
                </div>
            </div>
<!--            <div class="form-group">-->
<!--                <label class="font-noraml">选择有效期</label>-->
<!--                <div class="input-daterange input-group">-->
<!--                    <input type="text" name="startDate" th:value="${#dates.format(businessShopConfig.startDate, 'yyyy-MM-dd')}" class="input-sm form-control" id="datetimepicker-startTime" placeholder="yyyy-MM-dd"/>-->
<!--                    <span class="input-group-addon">到</span>-->
<!--                    <input type="text" name="endDate" th:value="${#dates.format(businessShopConfig.endDate, 'yyyy-MM-dd')}" class="input-sm form-control" id="datetimepicker-endTime" placeholder="yyyy-MM-dd"/>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">有效期选择：</label>
                <div class="input-group col-sm-8">
                    <input type="text" name="startDate" th:value="${#dates.format(businessShopConfig.startDate, 'yyyy-MM-dd')}" class="input-sm form-control" id="laydate-startTime" placeholder="yyyy-MM-dd"/>
                    <span class="input-group-addon">到</span>
                    <input type="text"  name="endDate" th:value="${#dates.format(businessShopConfig.endDate, 'yyyy-MM-dd')}"  class="input-sm form-control" id="laydate-endTime" placeholder="yyyy-MM-dd"/>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "system/business_config";
        $("#form-config-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            console.log("handler");
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-config-edit').serialize());
            }
        }
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            laydate.render({
                elem: '#laydate-demo-1'
            });

            laydate.render({
                elem: '#laydate-demo-2',
                type: 'date'
            });

            laydate.render({
                elem: '#laydate-demo-3',
                type: 'datetime',
                trigger: 'click'
            });

            laydate.render({
                elem: '#laydate-demo-4',
                range: true
            });

            var startDate = laydate.render({
                elem: '#laydate-startTime',
                max: $('#laydate-endTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 结束时间大于开始时间
                    if (value !== '') {
                        endDate.config.min.year = date.year;
                        endDate.config.min.month = date.month - 1;
                        endDate.config.min.date = date.date;
                    } else {
                        endDate.config.min.year = '';
                        endDate.config.min.month = '';
                        endDate.config.min.date = '';
                    }
                }
            });

            var endDate = laydate.render({
                elem: '#laydate-endTime',
                min: $('#laydate-startTime').val(),
                theme: 'molv',
                trigger: 'click',
                done: function(value, date) {
                    // 开始时间小于结束时间
                    if (value !== '') {
                        startDate.config.max.year = date.year;
                        startDate.config.max.month = date.month - 1;
                        startDate.config.max.date = date.date;
                    } else {
                        startDate.config.max.year = '';
                        startDate.config.max.month = '';
                        startDate.config.max.date = '';
                    }
                }
            });
        });


        function changeSelectType(){
            var type = $("#configType").val();
            console.log(type);
            if(type == 1){
                $("#divideType").show();
            }else {
                $("#divideType").hide();
            }
        }
    </script>
</body>
</html>